import type { VbenFormSchema } from '@vben/common-ui';

import type { VxeGridPropTypes } from '#/adapter/vxe-table';

export const columns: VxeGridPropTypes.Columns = [
  {
    title: '分类主键',
    field: 'categoryId',
    width: 100,
  },
  {
    title: '父级分类ID',
    field: 'parentId',
    width: 100,
  },
  {
    title: '分类名称',
    field: 'categoryName',
    minWidth: 160,
  },
  {
    title: '分类描述',
    field: 'categoryDescription',
    minWidth: 160,
  },
  {
    title: '图标',
    field: 'icon',
    minWidth: 50,
    slots: {
      default: ({ row }) => {
        if (row.icon) {
          return row.icon.includes('https') ? (
            <img src={row.icon} style={'max-width: 20px;margin: 0 auto'} />
          ) : (
            row.icon
          );
        }
      },
    },
  },
  {
    title: '显示顺序',
    field: 'orderNum',
    width: 100,
  },
  {
    title: '面试题数',
    field: 'interviewCount',
    width: 100,
  },
  {
    title: '状态',
    field: 'status',
    width: 100,
    align: 'center',
    slots: {
      default: 'status',
    },
  },
  {
    title: '创建时间',
    field: 'createTime',
    width: 160,
  },
  {
    title: '操作',
    field: 'action',
    fixed: 'right',
    width: 160,
    slots: {
      default: 'action',
    },
  },
];

export function querySchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'categoryName',
      label: '分类名称',
      component: 'Input',
    },
    {
      fieldName: 'parentId',
      label: '父级分类',
      component: 'TreeSelect',
      componentProps: {
        treeData: [],
        fieldNames: { label: 'categoryName', value: 'categoryId' },
        treeDefaultExpandAll: true,
        treeLine: { showLeafIcon: true },
        treeNodeLabelProp: 'fullName',
        showSearch: true,
        placeholder: '请选择父级分类',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        options: [
          {
            label: '正常',
            value: '0',
          },
          {
            label: '停用',
            value: '1',
          },
        ],
      },
    },
  ];
}
